<?php

/*
 +-------------------------------------------------------------------+
 |                   register.ctl.php                                |
 |                                                                   |
 | Copyright ?                          www.gde.sclab.clarkson.edu   |
 | Author: Demetrios Dimatos            www.dimatos.net              |
 | Created: August 2006                 Last modified: Oct 15, 2006  |
 +-------------------------------------------------------------------+
 | This is the control file for register.php that contains all the   |
 | logic.                                                            |
 |  - /gde-1.0/templates/public/register.php                         |
 +-------------------------------------------------------------------+
*/

 // Start the SESSION vars
 if (session_id() == "")
 {
	 session_start();
 }
 // Include configuration variables
 include_once('/var/www/gde-1.0/htdocs/config.php');
 // Include database connnection
 include_once(Config::base_path.Config::database_path."database.php");
 // Include user functions
 include_once(Config::base_path.Config::user_func_path."user.php");
 // Include html functions
 include_once(Config::base_path.Config::database_path."html.php");
 
  // Create the database connection, remember db_connect is not a class
 $db = db_connect(Config::db_type,Config::db_host,Config::db_username,Config::db_password,Config::db_database,0);
 
 // Create a user 
 $user = new User();
 
 // Lets see if the user is valid
 $answer = $user->RegisterUser($_POST['firstname'], $_POST['lastname'], $_POST['username'], $_POST['password'], $_POST['retype_passwd'],$_POST['email'],$db);
  
 if($answer == "empty")
 {
 	 message2html("\n[ You haven not completed all the registration fields. ]\n","red");
 	 message2url("Go to registration page.", 'http://'.$_SERVER['HTTP_HOST'].Config::url_public."register.php");
 }
 elseif ($answer == "missmatch")
 {
 	 message2html("\n[ You have entered two different passwords. ]\n","red");
 	 message2url("Go to registration page.", 'http://'.$_SERVER['HTTP_HOST'].Config::url_public."register.php");
 }
 elseif ($answer == "duplicate")
 {
 	 message2html("\n[ You have entered a user name already in use. ]\n","red");
	 message2url("Go to registration page.", 'http://'.$_SERVER['HTTP_HOST'].Config::url_public."register.php"); 	 
 }
 elseif ($answer == "valid")
 {
 	 // Register the login username
 	 $_SESSION['username'] = $_POST['username'];
 	 
 	 // Register the login password
 	 $_SESSION['password'] = $_POST['password'];
 	 
 	 // Register the login password
 	 $_SESSION['email'] = $_POST['email'];
 	 
 	 // Send logged in user to the authenticated part of the site.
 	 header("Location: ".Config::url_public."confirm.php");
 }
?>